﻿using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using WinRTControl.Extensions;

namespace WinRTControl.Navigation
{
    public class NFrame : ContentControl, INavigate
    {

        private const int DefaultCacheSize = 10;

        #region DependencyProperties

        #region CanGoBackDependencyProperty
        public bool CaGoBack
        {
            get { return (bool)GetValue(CaGoBackProperty); }
            internal set { this.SetValueNoCallBack(CaGoBackProperty, value); }
        }

        public static readonly DependencyProperty CaGoBackProperty =
            DependencyProperty.Register("CaGoBack", typeof(bool), typeof(NFrame), new PropertyMetadata(new PropertyChangedCallback(OnReadOnlyPropertyChanged)));

        private static void OnReadOnlyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            NFrame frame = d as NFrame;
            if (frame != null && !frame.AreHandlersSuspended())
            {
                frame.SetValueNoCallBack(e.Property, e.OldValue);
                throw new InvalidOperationException(e.Property.ToString() + "is readonly property");
            }
        }
        #endregion

        #region CanGoForwardDependencyProperty

        public bool CanGoForward
        {
            get { return (bool)GetValue(CanGoForwardProperty); }
            set { SetValue(CanGoForwardProperty, value); }
        }

        public static readonly DependencyProperty CanGoForwardProperty =
            DependencyProperty.Register("CanGoForward", typeof(bool), typeof(NFrame), new PropertyMetadata(new PropertyChangedCallback(OnReadOnlyPropertyChanged)));


        #endregion

        #region CacheSizeDependencyProperty

        public int CacheSize
        {
            get { return (int)GetValue(CacheSizeProperty); }
            set { SetValue(CacheSizeProperty, value); }
        }

        public static readonly DependencyProperty CacheSizeProperty =
            DependencyProperty.Register("CacheSize", typeof(int), typeof(NFrame), new PropertyMetadata(new PropertyChangedCallback(OnCacheSizeChanged)));


        private static void OnCacheSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Frame frame = (Frame)d;
            if (!frame.AreHandlersSuspended())
            {
                int num = (int)e.NewValue;
                if (num < 0)
                {
                    frame.SetValueNoCallBack(NFrame.CacheSizeProperty, e.OldValue);
                    throw new InvalidOperationException("Cache size must > 0!");
                }
             }
         }

        #endregion
       

        #endregion
       



        #region Implement

        public bool Navigate(Type sourcePageType)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region Method

        #endregion
        
    }
}
